// 用 synchronized 修饰 保证并发安全性
public class SellTicket_safe implements Runnable {
        private int ticket = 100;
        private Object obj = new Object();
        @Override
        public void run() {
            while(true){

                   synchronized (obj){
                       if(ticket > 0){
                           try {
                               Thread.sleep(100);
                           } catch (InterruptedException e) {
                               throw new RuntimeException(e);
                           }
                           System.out.println(Thread.currentThread().getName() + " is selling ticket " + ticket + " !");
                           ticket--;
                       }
                   }

                }
        }
    }


